package com.zoo.diannaopeijian.controller.entry;

import com.zoo.diannaopeijian.comm.page.Page;
import com.zoo.diannaopeijian.controller.BaseController;
import com.zoo.diannaopeijian.domain.Entryitem;
import com.zoo.diannaopeijian.service.EntryItemService;
import com.zoo.diannaopeijian.service.EntryService;
import com.zoo.diannaopeijian.service.EntryrecordService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by zx583 on 2018-01-22.
 */
@Controller
@RequestMapping("Entry")
public class EntryController extends BaseController {
    @Resource
    private EntryService entryService;
    @Resource
    private EntryrecordService entryrecordService;
    @Resource
    private EntryItemService entryItemService;

    @RequestMapping("EntryPage")
    public String EntryPageRoute() {
        return "/entry/EntryPage";
    }

    @RequestMapping("ReEntryPage")
    public String ReEntryPageRoute() {
        return "/entry/ReEntryPage";
    }

    @RequestMapping("EntryRecordPage")
    public String EntryRecordPageRoute() {
        return "/entry/EntryRecordPage";
    }

    @RequestMapping("EntryItemPage")
    public String EntryItemPageRoute() {
        return "/entry/EntryItemPage";
    }

    @RequestMapping(value = "/EntryWares")
    @ResponseBody
    public String EntryWares(@RequestBody List<Entryitem> entryItems) {
        return entryService.EntryWares(getLoginId(), entryItems) ? success : fail;
    }

    @RequestMapping(value = "/ReEntryWares")
    @ResponseBody
    public String ReEntryWares(@RequestBody List<Entryitem> entryItems) {
        return entryService.ReEntryWares(entryItems) ? success : fail;
    }

    @RequestMapping(value = "/getEntryRecord")
    // 2018-01-31 16:48:40
    @ResponseBody
    public Map getEntryRecord(Page page, @DateTimeFormat(pattern  = "yyyy-MM-dd") Date from, @DateTimeFormat(pattern  = "yyyy-MM-dd") Date to, String staffname) {
        return buildPageResult(entryrecordService.getEntryRecordWithPage(from, to, staffname, page));
    }

    @RequestMapping("/getEntryItems")
    @ResponseBody
    public List getEntryItems(Integer entryrecordid) {
        return entryItemService.getEntryItemsByRecordId(entryrecordid);
    }
}
